package cn.laike.modules.dev.controller;

import java.util.Arrays;
import java.util.Map;

import cn.laike.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.laike.modules.dev.entity.RecommendMoneyLogEntity;
import cn.laike.modules.dev.service.RecommendMoneyLogService;
import cn.laike.common.utils.PageUtils;
import cn.laike.common.utils.R;



/**
 * 推荐佣金记录
 *
 * @author ziye
 * @email 524748907@qq.com
 * @date 2019-03-26 17:07:15
 */
@RestController
@RequestMapping("dev/recommendmoneylog")
public class RecommendMoneyLogController {
    @Autowired
    private RecommendMoneyLogService recommendMoneyLogService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("dev:recommendmoneylog:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = recommendMoneyLogService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("dev:recommendmoneylog:info")
    public R info(@PathVariable("id") Integer id){
        RecommendMoneyLogEntity recommendMoneyLog = recommendMoneyLogService.selectById(id);

        return R.ok().put("recommendMoneyLog", recommendMoneyLog);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("dev:recommendmoneylog:save")
    public R save(@RequestBody RecommendMoneyLogEntity recommendMoneyLog){
        recommendMoneyLogService.insert(recommendMoneyLog);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("dev:recommendmoneylog:update")
    public R update(@RequestBody RecommendMoneyLogEntity recommendMoneyLog){
        ValidatorUtils.validateEntity(recommendMoneyLog);
        recommendMoneyLogService.updateAllColumnById(recommendMoneyLog);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("dev:recommendmoneylog:delete")
    public R delete(@RequestBody Integer[] ids){
        recommendMoneyLogService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
